package uk.co.threekelvin.perihelion.entities;

import java.awt.Rectangle;

import uk.co.threekelvin.perihelion.engine.World;

public class EntBase {
	private boolean valid = false;
	private int entID;
	private String type = "Base";
	private World world;
	private double x, y;
	private double vx, vy;
	private double m;

	public EntBase(World world) {
		this.world = world;

		EntBase[] ents = world.getAllEnts();
		for (int i = 0; i < ents.length; i++) {
			if (ents[i] == null) {
				ents[i] = this;
				this.entID = i;
				break;
			}
		}
	}

	public void spawn(double x, double y, double vx, double vy, double m) {
		this.valid = true;
		this.x = x;
		this.y = y;
		this.vx = vx;
		this.vy = vy;
		this.m = m;
	}

	public boolean isValid() {
		return this.valid;
	}

	public int entID() {
		return this.entID;
	}

	public String type() {
		return this.type;
	}

	public void setPos(double x, double y) {
		this.x = x;
		this.y = y;
	}

	public double[] getPos() {
		return new double[] { this.x, this.y };
	}

	public void setVel(double vx, double vy) {
		this.vx = vx;
		this.vy = vy;
	}

	public double[] getVel() {
		return new double[] { this.vx, this.vy };
	}

	public void setMass(double m) {
		this.m = m;
	}

	public double getMass() {
		return this.m;
	}

	public boolean collidingWith(EntBase entity) {
		if (!this.getBounds().intersects(entity.getBounds())) return false;
		return true;
	}

	public Rectangle getBounds() {
		// TODO return bounding rectangle of entity properly
		return new Rectangle(0, 0, 0, 0);
	}

	public void doCollide() {

	}

	public void think() {
		if (!valid) return;
	}

	public void draw() {
		if (!valid) return;
	}
}
